<?php
//----------------------------------------------------------------------------//
// Class              : Ctl_Content											  //
// Modification       :	Dang Thanh update lang 2008.01.21					  //
//----------------------------------------------------------------------------//
// Date(yyyy.mm.dd)   Developer                       Action				  //
//----------------------------------------------------------------------------//
// 2008.01.21         Dang Thanh                     Created				  //
//----------------------------------------------------------------------------//

class Ctl_Content extends ControlBase{
    var $modul="content";
	//==========================================================================
	// Function    : Control_Gopy
	// Argument    :
	// ReturnValue :
	// Creator     : Tran Thanh 2007.03.12
	// Details     : AppendData record of table
	//==========================================================================
	function Control_Content(){
	   	ControlBase::ControlBase();
	}

	//==========================================================================
	// Function    :  execute
	// Argument    :
	// ReturnValue :
	// Creator     : Tran Thanh 2007.03.12
	// Details     : AppendData record of table
	//==========================================================================
 	function execute($action=""){
	    global $db;
	    global     $arrayError,$_POST;
	    $arrayData =  array();
		$arrayData1 =  array();
		$arrayData2 =  array();
	    $this->modul = CM_getParameter(MODUL);
 		if ($action==""){
 			$action = CM_getParameter(ACTION);
 		}
		$listField="id,cat_id,title,introtext,fulltexts,images,cost,currency,created_date,hits";
		// Get data
		include_once(DIR_MODEL."md_content.class.php");
		$objModel = new MD_Content($this->db);
 		switch($action){
			case "SearchCatContent":
				
				$id = CM_getParameter("id");
				if(trim($id)!=""){
					$arrayData = $objModel->getByWhere($listField,"cat_id=".$id." and shows=1","id desc");
				}
				$cat_id = CM_getParameter("cat_id");
				include_once(DIR_MODEL."md_cat_content.class.php");
				$objcatContent = new MD_CatContent($db);
				$arrayData_catContent =  array();      
				$arrayData_catContent = $objcatContent->getById($cat_id);
				//print_r($arrayData_catContent);
  			    
				include_once(DIR_VIEW."v_content_list.php");
				V_ContentList($arrayData,$action,$arrayData_catContent);
				break;
			case "SearchText":
			
				$textfield = CM_getParameter("textfield");
				if(trim($textfield)!=""){
					$arrayData = $objModel->getForSearchText($textfield);
				}
  			    
				include_once(DIR_VIEW."v_content_list.php");
				V_ContentList($arrayData,$action,$arrayData_catContent);
				break;
			case "View":
				//echo "vao ham view";
				include_once(DIR_VIEW."v_content_view.php");
				$id = CM_getParameter("id");
				$cat_id = CM_getParameter("cat_id");
                $arrayData = $objModel->getFullById($id);
				
                if(empty($arrayData)){
                    $arrayError[]="Không tìm thấy bản ghi nào";
                }
				include_once(DIR_MODEL."md_cat_content.class.php");
				$objcatContent = new MD_CatContent($db);
				$arrayData_catContent =  array();      
				$arrayData_catContent = $objcatContent->getById($arrayData['cat_id']);
				
               
				//unset($arrayData,$arrayData_catContent);
				
				$this->updateCountClick($id);
				
                $arrayData2 = $objModel->getByWhere($listField,"id<>'".$id."' and shows=1","id desc");
                  // show data
				if ($objModel->errno()){
                    $arrayError[]=$LANG["error"]["khong_tim_thay_ban_ghi"];
				}
				V_ContentView($arrayData,$arrayData_catContent,$arrayData2,"View");
				//V_ContentList2($arrayData2,$arrayData_catContent);
				//V_ContentList2($arrayData2);
				
				break;
			case "List":
			default :{

				$arrayData = $objModel->getByWhereLimit($listField,"shows=1","id desc","20");
  			   
				include_once(DIR_VIEW."v_content_list.php");
				V_ContentList($arrayData,$action,$arrayData_catContent);
			}
 		}
        unset($arrayData,$arrayData1, $arrayData2,$arrayData_catContent);
	}
	//==========================================================================
	// Function    :  update
	// Argument    :
	// ReturnValue :
	// Creator     : ThanhTX  2007.07.12
	// Details     : AppendData record of table
	//==========================================================================
 	function updateCountClick($id)
	{
        global     $arrayError,$_POST;	
   		$objModel = new MD_Content($this->db);
   		$objModel->updateCountClick(&$id);
     	if ($objModel->errno())
		{
             $arrayError[]= $objModel->error();
             return false;
     	}
	}
}
?>